<?php
/**
 * CONTENIDO extension pack (mpContenidoX), consists of multiple classes to
 * provide more features for Plugins/Modules.
 *
 * @package     mpContenidoX
 * @subpackage  PluginInstaller
 * @author      Murat Purc <murat@purc.de>
 * @copyright   Copyright (c) 2008-2012 Murat Purc (http://www.purc.de)
 * @license     http://www.gnu.org/licenses/gpl-2.0.html - GNU General Public License, version 2
 * @version     $Id: Factory.class.php 21 2012-07-16 21:33:14Z purcaholic $
 */


defined('CON_FRAMEWORK') or die('Illegal call');


/**
 * Plugin install file reader factory.
 *
 * @package     mpContenidoX
 * @subpackage  PluginInstaller
 * @author      Murat Purc <murat@purc.de>
 */
class mpPluginInstaller_Reader_Factory
{

    /**
     * Returns a instance of a plugin installer reader class
     *
     * @param   string  $filePathName
     * @return  mpPluginInstaller_Reader_Abstract
     * @throws  mpPluginInstaller_Exception  If install file is not supported
     */
    public static function getReader($filePathName)
    {
        $info = pathinfo($filePathName);
        if (!isset($info['extension']) || $info['extension'] == '') {
            throw new mpPluginInstaller_Exception('Invalid plugin install file');
        }

        switch (strtolower($info['extension'])) {
            case 'xml':
                return new mpPluginInstaller_Reader_ContainerXml($filePathName);
                break;
            case 'php':
                return new mpPluginInstaller_Reader_ContainerPhp($filePathName);
                break;
            case 'ini':
                return new mpPluginInstaller_Reader_ContainerIni($filePathName);
                break;
            default:
                throw new mpPluginInstaller_Exception('Plugin install file not supported');
                break;
        }
    }

}
